

import os
from flask import Flask, request

app = Flask(__name__)

music_dir = "/Users/peishuaishuai/Downloads/儿歌歌曲"


@app.route('/music')
def music():
    music_files = [file for file in os.listdir(music_dir)
                   if file.endswith(".mp3")]
    music_file = request.args.get("music_file")
    os.system(f'open "{music_dir}/{music_file}"')
    result = "<style>h3, a {font-size:100px;}</style>"
    result += f"""<h3>当前播放<br/>{music_file}</h3>"""
    for item in music_files:
        result += f"<a href='?music_file={item}'>{item}</a><br/>"
    return result

app.run(host="0.0.0.0", port=8888)
